package com.littleken.order.controller;

import com.littleken.order.dto.OrderDTO;
import com.littleken.order.message.StreamClient;
import com.littleken.order.utils.JsonData;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * mq消息发送
 */
@RestController
@RequestMapping("/msg")
public class SendMessageController {

   @Autowired
   private StreamClient streamClient;

    /**
     * 消息发送
     * @return
     */
    @GetMapping("/sendMessage")
    public JsonData process(){

        OrderDTO orderDTO  = new OrderDTO();

        orderDTO.setBuyerOpenid("1553587231952888888");

            streamClient.output().send(MessageBuilder.withPayload(orderDTO).build());

        return JsonData.success(orderDTO);
    }

/*    @GetMapping("/sendMessage")
    public JsonData process(){

        streamClient.output().send(MessageBuilder.withPayload("now : "+new Date()).build());

        return JsonData.success();
    }*/

}
